/*  ----------------------------------------------------------------------------
 *  Warren Moxley
 *  ----------------------------------------------------------------------------
 *  GoogleHelper
 *  ----------------------------------------------------------------------------
 *  File:       TranslateService.cs
 *  Author:     IT1SERVICES\wmoxley
 *  ----------------------------------------------------------------------------
	Licensed to the Apache Software Foundation (ASF) under one
       	or more contributor license agreements.  See the NOTICE file
       	distributed with this work for additional information
       	regarding copyright ownership.  The ASF licenses this file
       	to you under the Apache License, Version 2.0 (the
       	"License"); you may not use this file except in compliance
       	with the License.  You may obtain a copy of the License at

        http://www.apache.org/licenses/LICENSE-2.0

       	Unless required by applicable law or agreed to in writing,
       	software distributed under the License is distributed on an
       	"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
       	KIND, either express or implied.  See the License for the
       	specific language governing permissions and limitations
       	under the License. 
 *  ----------------------------------------------------------------------------
*/

namespace Google.Apis.Wrappers.Translate.Data {
    using System;
    using System.Collections;
    using System.Collections.Generic;
    
    
    public class DetectionsListResponse {
        
        private IList<DetectionsResource> detections;
        
        /// <summary>A detections contains detection results of several text</summary>
        [Newtonsoft.Json.JsonPropertyAttribute("detections")]
        public virtual IList<DetectionsResource> Detections {
            get {
                return this.detections;
            }
            set {
                this.detections = value;
            }
        }
    }
    
    /// <summary>An array of languages which we detect for the given text The most likely language list first.</summary>
    public class DetectionsResource {
    }
    
    public class LanguagesListResponse {
        
        private IList<LanguagesResource> languages;
        
        /// <summary>List of source/target languages supported by the translation API. If target parameter is unspecified, the list is sorted by the ASCII code point order of the language code. If target parameter is specified, the list is sorted by the collation order of the language name in the target language.</summary>
        [Newtonsoft.Json.JsonPropertyAttribute("languages")]
        public virtual IList<LanguagesResource> Languages {
            get {
                return this.languages;
            }
            set {
                this.languages = value;
            }
        }
    }
    
    public class LanguagesResource {
        
        private string language;
        
        private string name;
        
        /// <summary>The language code.</summary>
        [Newtonsoft.Json.JsonPropertyAttribute("language")]
        public virtual string Language {
            get {
                return this.language;
            }
            set {
                this.language = value;
            }
        }
        
        /// <summary>The localized name of the language if target parameter is given.</summary>
        [Newtonsoft.Json.JsonPropertyAttribute("name")]
        public virtual string Name {
            get {
                return this.name;
            }
            set {
                this.name = value;
            }
        }
    }
    
    public class TranslationsListResponse {
        
        private IList<TranslationsResource> translations;
        
        /// <summary>Translations contains list of translation results of given text</summary>
        [Newtonsoft.Json.JsonPropertyAttribute("translations")]
        public virtual IList<TranslationsResource> Translations {
            get {
                return this.translations;
            }
            set {
                this.translations = value;
            }
        }
    }
    
    public class TranslationsResource {
        
        private string detectedSourceLanguage;
        
        private string translatedText;
        
        /// <summary>Detected source language if source parameter is unspecified.</summary>
        [Newtonsoft.Json.JsonPropertyAttribute("detectedSourceLanguage")]
        public virtual string DetectedSourceLanguage {
            get {
                return this.detectedSourceLanguage;
            }
            set {
                this.detectedSourceLanguage = value;
            }
        }
        
        /// <summary>The translation.</summary>
        [Newtonsoft.Json.JsonPropertyAttribute("translatedText")]
        public virtual string TranslatedText {
            get {
                return this.translatedText;
            }
            set {
                this.translatedText = value;
            }
        }
    }
}
namespace Google.Apis.Wrappers.Translate {
    using System;
    using System.IO;
    using System.Collections.Generic;
    using Google.Apis;
    using Google.Apis.Discovery;
    
    
    public class TranslateService : Google.Apis.Discovery.IRequestExecutor, Google.Apis.Discovery.ISchemaAwareRequestExecutor {
        
        private Google.Apis.Discovery.IService genericService;
        
        private Google.Apis.Authentication.IAuthenticator authenticator;
        
        private const string Version = "v2";
        
        private const string Name = "translate";
        
        private const string BaseUri = "https://www.googleapis.com/language/translate/";
        
        private const Google.Apis.Discovery.DiscoveryVersion DiscoveryVersionUsed = Google.Apis.Discovery.DiscoveryVersion.Version_0_3;
        
        private Newtonsoft.Json.JsonSerializer newtonJsonSerilizer = null;
        
        private Detections detections;
        
        private Languages languages;
        
        private Translations translations;

        private string developerKey;

        public TranslateService(Google.Apis.Discovery.IService genericService, Google.Apis.Authentication.IAuthenticator authenticator, string developerKey) {
            this.genericService = genericService;
            this.authenticator = authenticator;
            this.detections = new Detections(this);
            this.languages = new Languages(this);
            this.translations = new Translations(this);
            this.developerKey = developerKey;
        }

        public TranslateService(Google.Apis.Authentication.IAuthenticator authenticator, string developerKey) : 
            this(new Google.Apis.Discovery.DiscoveryService(new Google.Apis.Discovery.WebDiscoveryDevice(new System.Uri(string.Format("https://www.googleapis.com/discovery/v0.3/describe/{0}/{1}", TranslateService.Name, TranslateService.Version)))).GetService(TranslateService.Version, TranslateService.DiscoveryVersionUsed, new Google.Apis.Discovery.FactoryParameterV0_3(null, TranslateService.BaseUri)), authenticator, developerKey) {
        }
        
        public TranslateService(string developerKey) : 
                this(new Google.Apis.Discovery.DiscoveryService(new Google.Apis.Discovery.WebDiscoveryDevice(new System.Uri(string.Format("https://www.googleapis.com/discovery/v0.3/describe/{0}/{1}", TranslateService.Name, TranslateService.Version)))).GetService(TranslateService.Version, TranslateService.DiscoveryVersionUsed, new Google.Apis.Discovery.FactoryParameterV0_3(null, TranslateService.BaseUri)), Google.Apis.Authentication.AuthenticatorFactory.GetInstance().GetRegisteredAuthenticator(), developerKey) {
        }
        
        private Newtonsoft.Json.JsonSerializer NewtonJsonSerilizer {
            get {
                if ((this.newtonJsonSerilizer == null)) {
                    Newtonsoft.Json.JsonSerializerSettings settings = new Newtonsoft.Json.JsonSerializerSettings();
                    settings.NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore;
                    this.newtonJsonSerilizer = Newtonsoft.Json.JsonSerializer.Create(settings);
                }
                return this.newtonJsonSerilizer;
            }
        }
        
        public virtual Detections Detections {
            get {
                return this.detections;
            }
        }
        
        public virtual Languages Languages {
            get {
                return this.languages;
            }
        }
        
        public virtual Translations Translations {
            get {
                return this.translations;
            }
        }
        
        public virtual System.IO.Stream ExecuteRequest(string resource, string method, string body, System.Collections.Generic.IDictionary<string, object> parameters) {
            Google.Apis.Requests.IRequest request = this.genericService.CreateRequest(resource, method);
            return request.WithDeveloperKey(developerKey).WithParameters(parameters).WithAuthentication(authenticator).WithBody(body).ExecuteRequest();
        }
        
        public virtual System.IO.Stream ExecuteRequest(string resource, string method, object body, System.Collections.Generic.IDictionary<string, object> parameters) {
            return this.ExecuteRequest(resource, method, this.ObjectToJson(body), parameters);
        }
        
        public virtual string ObjectToJson(object obj) {
            System.IO.TextWriter tw = new System.IO.StringWriter();
            this.NewtonJsonSerilizer.Serialize(tw, obj);
            return tw.ToString();
        }
        
        public virtual TOutput JsonToObject<TOutput>(System.IO.Stream stream)
         {
            System.IO.StreamReader streamReader = new System.IO.StreamReader(stream);
            string str = streamReader.ReadToEnd();
            try {
                Google.Apis.Util.StandardResponse<TOutput> response = Newtonsoft.Json.JsonConvert.DeserializeObject<Google.Apis.Util.StandardResponse<TOutput>>(str);
                if ((response.Data == null)) {
                    throw new System.ApplicationException(string.Format("Failed to get response from stream, error was [{0}]", response.Error));
                }
                return response.Data;
            }
            catch (System.Exception ex) {
                throw new System.ApplicationException(string.Format("Failed to generate object of type[{0}] from Json[{1}]", typeof(TOutput).Name, str), ex);
            }
        }
    }
    
    public class Detections {
        
        private Google.Apis.Discovery.ISchemaAwareRequestExecutor service;
        
        private const string Resource = "detections";
        
        private log4net.ILog logger = log4net.LogManager.GetLogger(typeof(Detections));
        
        public Detections(TranslateService service) {
            this.service = service;
        }
        
        /// <summary>Detect the language of text.</summary>
        /// <param name="q">Required - The text to detect</param>
        public virtual System.IO.Stream List(string q) {
            string body = null;
            System.Collections.Generic.Dictionary<string, object> parameters = new System.Collections.Generic.Dictionary<string, object>();
            parameters["q"] = q;
            logger.Debug("Executing detections.list");
            System.IO.Stream ret = this.service.ExecuteRequest(Detections.Resource, "list", body, parameters);
            logger.Debug("Done Executing detections.list");
            return ret;
        }
        
        /// <summary>Detect the language of text.</summary>
        /// <param name="q">Required - The text to detect</param>
        public virtual Google.Apis.Wrappers.Translate.Data.DetectionsListResponse ListAsObject(string q) {
            string body = null;
            System.Collections.Generic.Dictionary<string, object> parameters = new System.Collections.Generic.Dictionary<string, object>();
            parameters["q"] = q;
            logger.Debug("Executing detections.list");
            Google.Apis.Wrappers.Translate.Data.DetectionsListResponse ret = this.service.JsonToObject<Google.Apis.Wrappers.Translate.Data.DetectionsListResponse>(this.service.ExecuteRequest(Detections.Resource, "list", body, parameters));
            logger.Debug("Done Executing detections.list");
            return ret;
        }
    }
    
    public class Languages {
        
        private Google.Apis.Discovery.ISchemaAwareRequestExecutor service;
        
        private const string Resource = "languages";
        
        private log4net.ILog logger = log4net.LogManager.GetLogger(typeof(Languages));
        
        public Languages(TranslateService service) {
            this.service = service;
        }
        
        /// <summary>List the source/target languages supported by the API</summary>
        /// <param name="target">Optional - the language and collation in which the localized results should be returned</param>
        public virtual System.IO.Stream List(string target) {
            string body = null;
            System.Collections.Generic.Dictionary<string, object> parameters = new System.Collections.Generic.Dictionary<string, object>();
            parameters["target"] = target;
            logger.Debug("Executing languages.list");
            System.IO.Stream ret = this.service.ExecuteRequest(Languages.Resource, "list", body, parameters);
            logger.Debug("Done Executing languages.list");
            return ret;
        }
        
        /// <summary>List the source/target languages supported by the API</summary>
        /// <param name="target">Optional - the language and collation in which the localized results should be returned</param>
        public virtual Google.Apis.Wrappers.Translate.Data.LanguagesListResponse ListAsObject(string target) {
            string body = null;
            System.Collections.Generic.Dictionary<string, object> parameters = new System.Collections.Generic.Dictionary<string, object>();
            parameters["target"] = target;
            logger.Debug("Executing languages.list");
            Google.Apis.Wrappers.Translate.Data.LanguagesListResponse ret = this.service.JsonToObject<Google.Apis.Wrappers.Translate.Data.LanguagesListResponse>(this.service.ExecuteRequest(Languages.Resource, "list", body, parameters));
            logger.Debug("Done Executing languages.list");
            return ret;
        }
        
        /// <summary>List the source/target languages supported by the API</summary>
        public virtual System.IO.Stream List(System.Collections.Generic.IDictionary<string, object> parameters) {
            string body = null;
            logger.Debug("Executing languages.list");
            System.IO.Stream ret = this.service.ExecuteRequest(Languages.Resource, "list", body, parameters);
            logger.Debug("Done Executing languages.list");
            return ret;
        }
    }
    
    public class Translations {
        
        private Google.Apis.Discovery.ISchemaAwareRequestExecutor service;
        
        private const string Resource = "translations";
        
        private log4net.ILog logger = log4net.LogManager.GetLogger(typeof(Translations));
        
        public Translations(TranslateService service) {
            this.service = service;
        }
        
        /// <summary>Returns text translations from one language to another.</summary>
        /// <param name="q">Required - The text to translate</param>
        /// <param name="target">Required - The target language into which the text should be translated</param>
        /// <param name="format">Optional - Must be one of the following values [html, text] - The format of the text</param>
        /// <param name="source">Optional - The source language of the text</param>
        public virtual System.IO.Stream List(string q, string target, string format, string source) {
            string body = null;
            System.Collections.Generic.Dictionary<string, object> parameters = new System.Collections.Generic.Dictionary<string, object>();
            parameters["q"] = q;
            parameters["target"] = target;
            parameters["format"] = format;
            parameters["source"] = source;
            logger.Debug("Executing translations.list");
            System.IO.Stream ret = this.service.ExecuteRequest(Translations.Resource, "list", body, parameters);
            logger.Debug("Done Executing translations.list");
            return ret;
        }
        
        /// <summary>Returns text translations from one language to another.</summary>
        /// <param name="q">Required - The text to translate</param>
        /// <param name="target">Required - The target language into which the text should be translated</param>
        /// <param name="format">Optional - Must be one of the following values [html, text] - The format of the text</param>
        /// <param name="source">Optional - The source language of the text</param>
        public virtual Google.Apis.Wrappers.Translate.Data.TranslationsListResponse ListAsObject(string q, string target, string format, string source) {
            string body = null;
            System.Collections.Generic.Dictionary<string, object> parameters = new System.Collections.Generic.Dictionary<string, object>();
            parameters["q"] = q;
            parameters["target"] = target;
            parameters["format"] = format;
            parameters["source"] = source;
            logger.Debug("Executing translations.list");
            Google.Apis.Wrappers.Translate.Data.TranslationsListResponse ret = this.service.JsonToObject<Google.Apis.Wrappers.Translate.Data.TranslationsListResponse>(this.service.ExecuteRequest(Translations.Resource, "list", body, parameters));
            logger.Debug("Done Executing translations.list");
            return ret;
        }
        
        /// <summary>Returns text translations from one language to another.</summary>
        /// <param name="q">Required - The text to translate</param>
        /// <param name="target">Required - The target language into which the text should be translated</param>
        public virtual System.IO.Stream List(string q, string target, System.Collections.Generic.IDictionary<string, object> parameters) {
            string body = null;
            parameters["q"] = q;
            parameters["target"] = target;
            logger.Debug("Executing translations.list");
            System.IO.Stream ret = this.service.ExecuteRequest(Translations.Resource, "list", body, parameters);
            logger.Debug("Done Executing translations.list");
            return ret;
        }
    }
}
